package com.chijun.mform.show;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.MenuProvider;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;

import com.alibaba.fastjson.JSON;
import com.chijun.mform.R;
import com.chijun.mform.test.CreateFormServiceImpl;
import com.example.ccj.b.a.BaseActivity;
import com.example.ccj.b.f.BaseFragment;
import com.example.ccj.u.server.MyObserver;
import com.example.ccj.u.server.Result;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

public class ShowFullDataActivity extends BaseActivity {


    @Override
    public void initData(@Nullable Bundle bundle) {

    }

    @Override
    public void initView(@Nullable Bundle bundle, @Nullable View view) {
        AllTheDataForAForm allTheDataForAForm = findViewById(R.id.activity_show_full_data_view);
        allTheDataForAForm.setData(576134266333958144L, new TheLoadFormHasBeenFilledWithDataCallback() {
            @Override
            public void onServerFormDataReturns(long formId, int startIndex, int count, WaitForTheCallbackToReturn callbackToReturn) {
                CreateFormServiceImpl.getInstance()
                        .getServerFormDataReturns(formId,startIndex,count)
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new MyObserver<Result>() {
                            @Override
                            public void onNext(Result result) {
                                callbackToReturn.onResult(result.getData());
                            }

                            @Override
                            public void onError(Throwable e) {
                                callbackToReturn.onError(e.getMessage());
                                super.onError(e);
                            }
                        });
            }
            @Override
            public void onError(String error) {

            }

            @Override
            public void onTheServerSearchesForFormDataReturns(long formId,String searchText, WaitForTheCallbackToReturn callbackToReturn) {
                CreateFormServiceImpl.getInstance()
                        .getServerSearchesForFormDataReturns(formId, searchText)
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new MyObserver<Result>() {
                            @Override
                            public void onNext(Result result) {
                                callbackToReturn.onResult(result.getData());
                            }

                            @Override
                            public void onError(Throwable e) {
                                callbackToReturn.onError(e.getMessage());
                                super.onError(e);
                            }
                        });
            }
        });
    }

    @Override
    public int initContentView() {
        return R.layout.activity_show_full_data;
    }

    @Override
    public void addMenuProvider(@NonNull MenuProvider provider, @NonNull LifecycleOwner owner, @NonNull Lifecycle.State state) {

    }
}